<template>
  <div class="item flex">
    <div>
      <input type="checkbox" v-model="data.isFinish" />
      <!-- 编辑的插槽 -->
      <slot name="editSlot"></slot>
      <span v-show="!data.isEdit">{{ data.txt }}</span>
      <input
        type="text"
        v-model="data.txt"
        v-if="data.isEdit"
        @keyup.enter="editFinish(data.id)"
        v-focus
        @blur="out(data.id)"
      />
    </div>
    <!-- 删除的插槽 -->
    <slot name="delSlot"></slot>
  </div>
</template>

<script>
export default {
  props: ["data"],
  methods: {
    editFinish(id) {
      this.$store.commit("editF", id);
    },
    out(id){
        this.$store.commit("out", id);
    }
  },
  directives: {
    focus: {
      bind(el, binding) {},
      inserted(el, binding) {
        el.focus();
      },
      update(el, binding) {},
    },
  },
};
</script>
 
<style>
.item {
  padding: 0 20px;
  background-color: #fff;
  height: 40px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.item [type="checkbox"] {
  margin-right: 10px;
}
</style>